{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.d48ea82345bd6b4038d8ffd19ef8b95e.315360000.1910861500.282335-21558245', 'expires_in': 2592000, 'session_key': '9mzdA8t3/mq1E5hTRO6DjP5+vZh0brBdcbhJtb693tdXsBHdbP0HVN0COIHKFoStpp+tfHKHWCwrJ6QShidgp9a1njKwDQ==', 'access_token': '24.8a16ed61c4889934636495c04085bc30.2592000.1598093500.282335-21558245', 'scope': 'public vis-classify_dishes vis-classify_car brain_all_scope vis-classify_animal vis-classify_plant brain_object_detect brain_realtime_logo brain_dish_detect brain_car_detect brain_animal_classify brain_plant_classify brain_ingredient brain_body_analysis brain_body_attr brain_advanced_general_classify brain_custom_dish brain_poi_recognize brain_vehicle_detect brain_redwine brain_currency brain_vehicle_damage wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理', 'session_secret': '57b7c7bf8dff4720c659f18496b49e33'}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>refresh_token</th>\n",
       "      <td>25.d48ea82345bd6b4038d8ffd19ef8b95e.315360000....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>expires_in</th>\n",
       "      <td>2592000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_key</th>\n",
       "      <td>9mzdA8t3/mq1E5hTRO6DjP5+vZh0brBdcbhJtb693tdXsB...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>access_token</th>\n",
       "      <td>24.8a16ed61c4889934636495c04085bc30.2592000.15...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>scope</th>\n",
       "      <td>public vis-classify_dishes vis-classify_car br...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>session_secret</th>\n",
       "      <td>57b7c7bf8dff4720c659f18496b49e33</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                                0\n",
       "refresh_token   25.d48ea82345bd6b4038d8ffd19ef8b95e.315360000....\n",
       "expires_in                                                2592000\n",
       "session_key     9mzdA8t3/mq1E5hTRO6DjP5+vZh0brBdcbhJtb693tdXsB...\n",
       "access_token    24.8a16ed61c4889934636495c04085bc30.2592000.15...\n",
       "scope           public vis-classify_dishes vis-classify_car br...\n",
       "session_secret                   57b7c7bf8dff4720c659f18496b49e33"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"\"\"\n",
    "文档形式专业程度-文档形式\n",
    "“专业排版-PRD文档以代码注释及markdown图文部分”：\n",
    "将代码片段改成markdown文本展示方便同行直接进行代码的学习调用。\n",
    "\"\"\"\n",
    "# encoding:utf-8\n",
    "import requests \n",
    "import pandas as pd\n",
    "import json\n",
    "\n",
    "# client_id 为官网获取的AK， client_secret 为官网获取的SK\n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=uIAOUqQBVzHm2kbMAFpUkl0b&client_secret=CfXqyXgxQo5lSYd3quhrjNtzzctdPmA8'\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())\n",
    "pd.json_normalize(response.json()).T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'person_num': 1, 'person_info': [{'body_parts': {'left_hip': {'y': 1199.22265625, 'x': 333.29296875, 'score': 0.552393913269043}, 'top_head': {'y': 479.92578125, 'x': 402.90234375, 'score': 0.854009747505188}, 'right_mouth_corner': {'y': 619.14453125, 'x': 426.10546875, 'score': 0.9005736112594604}, 'neck': {'y': 630.74609375, 'x': 344.89453125, 'score': 0.8398562669754028}, 'left_shoulder': {'y': 688.75390625, 'x': 321.69140625, 'score': 0.6338421702384949}, 'left_knee': {'y': 1535.66796875, 'x': 368.09765625, 'score': 0.3666496574878693}, 'left_ankle': {'y': 1709.69140625, 'x': 344.89453125, 'score': 0.2179663181304932}, 'left_mouth_corner': {'y': 619.14453125, 'x': 449.30859375, 'score': 0.9074334502220154}, 'right_elbow': {'y': 897.58203125, 'x': 356.49609375, 'score': 0.8767411112785339}, 'right_ear': {'y': 549.53515625, 'x': 356.49609375, 'score': 0.8717073202133179}, 'nose': {'y': 595.94140625, 'x': 460.91015625, 'score': 0.9047424793243408}, 'left_eye': {'y': 561.13671875, 'x': 460.91015625, 'score': 0.8656303882598877}, 'right_eye': {'y': 561.13671875, 'x': 437.70703125, 'score': 0.8749117255210876}, 'right_hip': {'y': 1199.22265625, 'x': 333.29296875, 'score': 0.6533549427986145}, 'left_wrist': {'y': 758.36328125, 'x': 507.31640625, 'score': 0.3235248923301697}, 'left_ear': {'y': 549.53515625, 'x': 356.49609375, 'score': 0.4898476004600525}, 'left_elbow': {'y': 920.78515625, 'x': 333.29296875, 'score': 0.4727270007133484}, 'right_shoulder': {'y': 665.55078125, 'x': 310.08984375, 'score': 0.8586969375610352}, 'right_ankle': {'y': 1709.69140625, 'x': 379.69921875, 'score': 0.2583350837230682}, 'right_knee': {'y': 1535.66796875, 'x': 391.30078125, 'score': 0.4297023415565491}, 'right_wrist': {'y': 758.36328125, 'x': 518.91796875, 'score': 0.8388108015060425}}, 'location': {'height': 1188.19140625, 'width': 505.128173828125, 'top': 437.2076416015625, 'score': 0.941042423248291, 'left': 133.2104187011719}}], 'log_id': 1662863385316405015}\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>person_num</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>person_info</th>\n",
       "      <td>[{'body_parts': {'left_hip': {'y': 1199.222656...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>log_id</th>\n",
       "      <td>1662863385316405015</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                             0\n",
       "person_num                                                   1\n",
       "person_info  [{'body_parts': {'left_hip': {'y': 1199.222656...\n",
       "log_id                                     1662863385316405015"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "人体关键点识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open(r'C:/users/acer/desktop/8_扫描.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token = '24.d80c8aaf00362a45e253c0bfb5c1194a.2592000.1598093428.282335-21558245'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "pd.json_normalize(response.json()).T\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 6797212505425389335, 'result': {'width': 522, 'top': 440, 'height': 1352, 'left': 131}}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "图像主体检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open( r'C:/users/acer/desktop/8_扫描.png','rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img,\"with_face\":1}\n",
    "access_token = '24.d80c8aaf00362a45e253c0bfb5c1194a.2592000.1598093428.282335-21558245'\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
